<?php
require 'Home/Model/Model.php';
	class IndexModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getType(){
			$sql='select * from newstype';
			$data=$this->conn->query($sql);
			return $data;
		}
		function showNews(){
			$sql='select a.ntid,a.nid,a.newsname,a.pic,b.typename from news a,newstype b where a.ntid=b.ntid ';
			//echo $sql;
			$data=$this->conn->query($sql);
			//var_dump($data);
			return $data;
		}
		function getRank(){
			$sql="select * from news order by hittimes desc limit 4";
			//echo $sql;
			return $this->conn->query($sql);
		}
		function addcomments($data){
			$uid=$data['uid'];
			$nid=$data['nid'];
		
			
        	$comment=$data['comment'];
        
        $sql=
        "insert into comments VALUES ('null','$uid','$nid','$comment')";
       // echo $sql;
        $result=$this->conn->query($sql);
        return $result;
    }
    function add($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  				}
			  else{
			  	$pic='';
			  }

			  $user = array(
					'uname' => trim($data['uname']),  
					'password' => $data['password'],
					'gender' => $data['gender'],
					'birthdate' => $data['birthdate'],
					'hobby' => implode($data['hobby'], ','),
					'degree' => $data['degree'],
					'intro' => $data['intro'],
					'pic'=>$pic
			  	);
			  

			  $keys = implode(',',array_keys($user));
			  $values = implode("','", array_values($user));
			  $sql="insert into users ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
			  
		}

		function getUserLogin($data){
		session_start();
		$uname=$_POST["uname"];
		$password=$_POST["password"];
   			$sql = "select * from users where uname='$uname'and password='$password'";
   			
   			$result=$this->conn->query($sql);
			  return $result;
    	
		}


		
	}
?>